<section class="sidebar">
    <!--<div class="user-panel">
        <div class="pull-left image">
            <img data-href="${ctx}/sys/user/info" data-title="${text('个人中心')}" class="img-circle pointer"
                src="${@user.getAvatarUrl().replaceFirst('/ctxPath', ctxPath)}">
            <script>
                $(function(){
                    if ($(window).width() <= 767){
                        $('body').append('<div class="btn btn-default full-screen-menu"><i class="fa fa-bars"></i></div>');
                    }
                    $('.full-screen-menu,.user-panel .img-circle').click(function(){
                        if (!$('.main-header').is(':hidden')){
                            $('.main-header').slideUp(100, function(){
                                if (($(window).width() > 767 && !$('body').hasClass('sidebar-collapse'))
                                        || $('body').hasClass('sidebar-open')){
                                    $('[data-toggle="push-menu"]').click();
                                }
                            });
                        }else{
                            $('.main-header').slideDown(100, function(){
                                setTimeout(function(){
                                    if (${@Global.getConfig('sys.index.sidebarStyle', '1') != '2'}){
                                        $('[data-toggle="push-menu"]').click();
                                    }
                                },100);
                            });
                        }
                        setTimeout(function(){
                            $('#tabpanel').tabPanel('resize');
                        },500);
                    });
                    $('#leftMenu').on('click', '.addTabPage', function (e) {
                        if ($(window).width() <= 767 && $('body').hasClass('sidebar-open')){
                            var href = $(this).data('href');
                            if (href != '' && href != 'blank'){
                                if ($(window).width() <= 767){
                                    $('.full-screen-menu').click();
                                }
                            }
                        }
                    });
                })
            </script>
        </div>
        <div class="pull-left info">
            <p>${user.userName}</p>
            <a href="javascript:"><i class="fa fa-circle text-success"></i> ${text('在线')}</a>
            <a href="${ctx}/logout"><i class="fa fa-sign-out text-danger"></i> ${text('注销')}</a>
        </div>
    </div>-->
    <%/*<!--%>
	<form action="#" method="get" class="sidebar-form">
		<div class="input-group">
			<input type="text" name="q" class="form-control" placeholder="查询...">
			<span class="input-group-btn">
				<button type="submit" name="search" id="search-btn" class="btn btn-flat"><i
					class="fa fa-search"></i></button>
			</span>
		</div>
	</form>
	<%--> */%>
    <%/*<!--%>
	<ul class="sidebar-menu">
		<% var menuSysCode = @ObjectUtils.toStringIgnoreNull(session.sysCode, 'default'); %>
		<li class="header">${@DictUtils.getDictLabel('sys_menu_sys_code', menuSysCode, '')}</li>
	</ul>
	<%--> */%>
    <div id="leftMenu" data-widget="tree">
        <% if(@Global.getConfig('sys.index.menuStyle', '1') == '1'){ %>
        <ul class="sidebar-menu">
            <%
            var p = {parentCode: '0'};
            menu.tree(p); print(p.html);
            %>
        </ul>
        <% } %>
    </div>
    <%/*<!--%>
	<ul class="sidebar-menu">
		<li class="header">快捷菜单</li>
		<li><a href="#"><i class="fa fa-circle-o text-red"></i> <span>快捷菜单1</span></a></li>
		<li><a href="#"><i class="fa fa-circle-o text-yellow"></i> <span>快捷菜单2</span></a></li>
		<li><a href="#"><i class="fa fa-circle-o text-aqua"></i> <span>快捷菜单3</span></a></li>
	</ul>
	<%--> */%>
</section>

<script>
    //监听本地存储 RISKID 键 值
    // var a =$('.sidebar-menu li a')
    // var arr=[]
    // var arr1=[]
    // var arr2=[]
    // localStorage.setItem('dat','000')
    // window.addEventListener('storage',function (e) {
    // 	//获取被修改的键值
    // 	if (e.key == 'dat') {
    //
    // 		if (e.newValue!='000'){
    // 			$('.sidebar-menu li a span').remove('.ss')
    // 			gg()
    // 		}
    // 	}
    // },false);


    // var b=[]
    function arrFilter(info) {
        // 定义需要查询的选项
        var result = []
        for (key in info) {
            if (info[key] == '任务确认') {
                result.push("1")
                continue
            }
            if (info[key] == '任务阶段目标报送') {
                result.push("2")
                continue
            }
            if (info[key] == '任务接收') {
                result.push("3")
                continue
            }
            if (info[key] == '任务待办') {
                result.push("4")
                continue
            }
            if (info[key] == '待办批示') {
                result.push("5")
                continue
            }
            if (info[key] == '任务部署审核') {
                result.push("6")
                continue
            }
            if (info[key] == '任务反馈审核') {
                result.push("7")
                continue
            }
            if (info[key] == '阶段目标报送审核') {
                result.push("8")
                continue
            }
            if (info[key] == '任务整理审核') {
                result.push("9")
                continue
            }
            if (info[key] == '关键指标报送') {
                result.push("10")
                continue
            }
            if (info[key] == '单项指标报送') {
                result.push("11")
                continue
            }
            if (info[key] == '细则报送') {
                result.push("12")
                continue
            }
            if (info[key] == '关键指标评分') {
                result.push("13")
                continue
            }
            if (info[key] == '单项指标评分') {
                result.push("14")
                continue
            }
            if (info[key] == '指标审核') {
                result.push("15")
                continue
            }

        }
        return result;
    }


    function sumCount(type, arr, name,cc,dd) {
        let sumNum = 0
        for (key in arr) {
            // 展示在【过程审核】菜单上的角标值
            if (type == '1') {
                if (arr[key].name == '任务部署审核' || arr[key].name == '任务反馈审核' || arr[key].name == '任务整理审核' || arr[key].name == '阶段目标报送审核') {
                    sumNum = sumNum + arr[key].value
                    continue
                }
                // 展示在【指标报送】菜单上的角标值
            } else if (type == '2') {
                if (arr[key].name == '关键指标报送' || arr[key].name == '单项指标报送' || arr[key].name == '细则报送') {
                    sumNum = sumNum + arr[key].value
                    continue
                }
            } else if (type == '3') {
                if ((cc&&dd)&&arr[key].name == '关键指标评分' || arr[key].name == '单项指标评分') {
                    sumNum = sumNum + arr[key].value
                    continue
                }
                if (cc&&arr[key].name == '关键指标评分' ) {
                    sumNum = arr[key].value
                    continue
                }
                if (dd&&arr[key].name == '单项指标评分' ) {
                    sumNum =  arr[key].value
                    continue
                }
            } else {
                if (arr[key].name == name) {
                    sumNum = arr[key].value
                    break
                }
            }
        }
        return sumNum
    }

    const gg = function () {
        var a = $('.sidebar-menu li a')
        var data_info = []
        // 获取当前用户 需要展示角标的菜单页面
        for (key in a) {
            if (a[key].innerText != null) {
                data_info.push(a[key].innerText.trim())
            }
        }
        var arr = []
        var arr1 = []
        var arr2 = []
        $.ajax({
            type: 'post',
            url: "${ctx}/menu/act/statics3",
            data: {
                list: JSON.stringify(arrFilter(data_info))
            },
            success: function (res) {
                b = res
                // 获取后台返回的角标数值
                $.each(b, function (key, value) {
                    arr.push({
                        name: key,
                        value: value
                    })
                })
                arr.push({
                    name: "过程审核",
                    value: 0
                })
                arr.push({
                    name: "督查督办",
                    value: 0
                })
                // 获取页面上展示的菜单
                var c = false ;var d = false

                for (let i = 0; i < a.length; i++) {
                    var t = a.eq(i)[0].innerText.trim()
                    if(t=='关键指标评分'){
                        c=true
                    }
                    if(t=='单项指标评分'){
                        d=true
                    }
                    arr1.push(t)
                }
                // 吴公度编写代码
                // var process=0;
                // var task=0;
                // var processIndex;
                // var taskIndex;
                // arr.forEach(function(item,index){
                //
                // 	arr1.forEach(function(item1,index1){
                // 		if (item.name==item1){
                // 			// 展示在【督查督办】菜单上的角标值
                // 			task = task+item.value;
                // 			// 展示在【过程审核】菜单上的角标值
                // 			if(item1=='任务部署审核' || item1=='任务反馈审核'|| item1=='任务整理审核'|| item1=='任务细化分解审核'){
                // 				process = process+item.value;
                // 			}
                // 			if(item.name=='过程审核'){
                // 				processIndex =index1;
                // 			}
                // 			if(item.name=='督查督办'){
                // 				taskIndex =index1;
                // 			}
                // 			// console.log(index1)
                // 			arr2.push({
                // 				num:index1,
                // 				value:item.value
                // 			})
                // 		}
                // 	})
                // })
                // 目标考核角标汇总
                let ducha_nums = 0;
                let ducha_index = 0;
                // 目标考核角标汇总
                let kaohe_nums = 0;
                let kaohe_index = 0;
                for (i in arr1) {
                    // 用来计算 父菜单角标的数据
                    let sumNum = 0;
                    if (arr1[i] == '过程审核') {
                        sumNum = sumCount("1", arr)
                        ducha_nums = ducha_nums + sumNum;
                    } else if (arr1[i] == '指标报送') {
                        sumNum = sumCount("2", arr)
                        kaohe_nums = kaohe_nums + sumNum;
                    } else if (arr1[i] == '考核评分') {
                        sumNum = sumCount("3", arr,null,c,d)
                        kaohe_nums = kaohe_nums + sumNum;
                    } else {
                        sumNum = sumCount("4", arr, arr1[i])
                        if (
                            arr1[i] == '任务接收' ||
                            arr1[i] == '任务待办' ||
                            arr1[i] == '待办批示' ||
                            arr1[i] == '任务确认' ||
                            arr1[i] == '任务阶段目标报送'
                        ) {
                            ducha_nums = ducha_nums + sumNum;
                        }

                        if (arr1[i] == '指标审核') {
                            kaohe_nums = kaohe_nums + sumNum;
                        }

                    }
                    if (arr1[i] == '督查督办') {
                        ducha_index = i;
                    }
                    if (arr1[i] == '目标考核') {
                        kaohe_index = i;
                    }

                    arr2.push({
                        num: i,
                        value: sumNum
                    })
                }
                arr2.forEach(function (item) {
                    // 注释部分为 吴公度 编写代码
                    if (item.num == ducha_index) {
                        item.value = ducha_nums
                    }
                    if (item.num == kaohe_index) {
                        item.value = kaohe_nums
                    }
                    if (item.value > 0) {
                        if (item.value > 99) {
                            item.value = '99+'
                        }
                        a.eq(item.num).append(
                            '<span class="ss">' +
                            item.value +
                            '</span>'
                        )
                    }

                })
            }
        })
    }


    gg()

</script>

<style>
    .ss {
        color: #ffffff;
        text-align: center;
        width: 20px;
        height: 20px;
        background-color: #f56c6c;
        border-radius: 50%;
        position: absolute;
        right: 0px;
        padding-top: 1px;
        font-size: 10px;
    }
</style>


